package com.lcf.framework.utils;

import com.lcf.mybatisplus.handler.TenantHandler;

import java.util.function.Supplier;

/**
 * 描述：租户工具类
 *
 * @author lcf
 * @since 2025/4/29 22:07
 */
public class TenantUtils {
    /**
     * 临时忽略租户id
     */
    public static void ignoreTenantId(Runnable runnable) {
        try {
            TenantHandler.MybatisTenantContext.ignore();
            runnable.run();
        } finally {
            TenantHandler.MybatisTenantContext.clear();
        }
    }

    /**
     * 临时忽略租户id
     */
    public static <T> T ignoreTenantId(Supplier<T> supplier) {
        try {
            TenantHandler.MybatisTenantContext.ignore();
            return supplier.get();
        } finally {
            TenantHandler.MybatisTenantContext.clear();
        }
    }
}
